import maya.cmds as cmds

def switch_to_shotcam():
    camera_name = "ShotCam"
    
    # 1. Check if the camera actually exists in the scene
    if not cmds.objExists(camera_name):
        cmds.warning(f"Looking for '{camera_name}', but it doesn't exist!")
        return

    # 2. Find the active 3D modeling panel (the one you are looking at)
    active_panel = cmds.getPanel(withFocus=True)
    panel_type = cmds.getPanel(typeOf=active_panel)

    # 3. Ensure the focused panel is actually a modelEditor (a 3D viewport)
    if panel_type == 'modelPanel':
        cmds.modelEditor(active_panel, edit=True, camera=camera_name)
        print(f"Switched {active_panel} to {camera_name}")
    else:
        # If the focus isn't on the viewport, find the first visible one
        visible_panels = cmds.getPanel(visiblePanels=True)
        for panel in visible_panels:
            if cmds.getPanel(typeOf=panel) == 'modelPanel':
                cmds.modelEditor(panel, edit=True, camera=camera_name)
                print(f"Switched {panel} to {camera_name}")
                break

switch_to_shotcam()